#include "RingQueue.hpp"

using namespace std;

void* Producer(void* arg)
{
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(arg);
    while(true)
    {
        int data = rand() % 10 + 1;
        rq->Push(data);
        cout << "Producer data done, data is: " << data << endl;
        sleep(1);
    }
    return nullptr;
}

void* Consumer(void* arg)
{
    sleep(2);
    RingQueue<int>* rq = static_cast<RingQueue<int>*>(arg);
    while(true)
    {
        int data = rq->Pop();
        cout << "Consumer get data , data is: " << data << endl;
        sleep(1);
    }
    return nullptr;
}

int main()
{
    srand((unsigned int)time(nullptr) ^ getpid());
    RingQueue<int>* rq = new RingQueue<int>();
    pthread_t c, p;
    
    pthread_create(&p, nullptr, Producer, rq);
    pthread_create(&c, nullptr, Consumer, rq);

    pthread_join(p, nullptr);
    pthread_join(c, nullptr);   

    return 0;
}